package com.freewater.springboot.demo.spel.assignment;

import com.freewater.springboot.demo.spel.Inventor;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.SimpleEvaluationContext;

public class Main {
    public static void main(String[] args) {
        Inventor inventor = new Inventor();
        EvaluationContext context = SimpleEvaluationContext.forReadWriteDataBinding().build();
        ExpressionParser parser = new SpelExpressionParser();
        parser.parseExpression("name").setValue(context, inventor, "Aleksandar Seovic");
        System.out.println(inventor.getName());

        parser.parseExpression("name='Aleksandar Seovic Again'").getValue(context, inventor, String.class);
        System.out.println(inventor.getName());
    }
}
